package org.leetcode.easy.leetcode66;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution2 {

    public static void main(String[] args) {

//        int num =  12;
//        System.out.println(num / 10);
//        System.out.println(num % 10);

        int [] test = {1,2,3};

        for (int num : plusOne(test)) {
            System.out.println(num);
        }


    }
    public static int[] plusOne(int[] digits) {
        List<Integer> list = new ArrayList<>();
        int carry = 1;
        int index = digits.length - 1;

        while (index >= 0) {
            int num = digits[index] + carry ;
            carry = num / 10;
            num = num % 10;
            list.add(num);
            index --;
        }
        if (carry != 0) {
            list.add(carry);
        }
        int n = list.size();
        int[] res = new int[n];

        for (int i = n - 1; i >= 0; i--) {
            res[n-1-i] = list.get(i);
        }

        return res;
    }
}
